package api

import (
	"encoding/gob"

	"gitee.com/chenrh/finego/api/dingding"
	"gitee.com/chenrh/finego/api/miniprogram"
	"gitee.com/chenrh/finego/api/wxwoa"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
)

// RegisteRouters 注册路由
func RegisteRouters(app *iris.Application) {
	// 当使用 utils.SetCache 一个结构体实例时，必须要先注册
	gob.Register(&wxwoa.WxConfig{})

	wx := mvc.New(app.Party("/wx"))
	// wx.Router.SetExecutionRules(iris.ExecutionRules{
	// 	// Begin:  <- from `Use[all]` to `Handle[last]` future route handlers, execute all, execute all even if `ctx.Next()` is missing.
	// 	// Main:   <- all `Handle` future route handlers, execute all >> >>.
	// 	Done: iris.ExecutionOptions{Force: true}, // <- from `Handle[last]` to `Done[all]` future route handlers, execute all >> >>.
	// })
	// wx.Router.Done(doneHandler)
	wx.Handle(new(wxwoa.WxTokenCheckController))
	wx.Handle(new(wxwoa.WxAuthorizeController))
	wx.Handle(new(wxwoa.WxIndexController))
	wx.Handle(new(wxwoa.WxMenuController))
	wx.Handle(new(wxwoa.WxLocationController))
	wx.Handle(new(wxwoa.WxShareController))
	wx.Handle(new(wxwoa.WxTemplateMessageController))

	app.PartyFunc("/wx", func(wxapi iris.Party) {
		wxapi.Any("/test", index)
	})

	mp := mvc.New(app.Party("/mp"))
	mp.Handle(new(miniprogram.MpSession))
	app.PartyFunc("/mp", func(pt iris.Party) {
		pt.Any("/test", index)
	})

	dd := mvc.New(app.Party("/dd"))
	dd.Handle(new(dingding.DingDingAuthController))

	app.PartyFunc("/dd", func(pt iris.Party) {
		pt.Any("/test", index)
	})

}

func index(ctx iris.Context) {
	ctx.HTML("<h1 style='color:green;'>恭喜您，接口网络通畅(MP)</h1>")
}
